﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.InputOutput.Encryption
Imports AugmentLib.WebComponent

Partial Class UploadView
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("StaffId") Is Nothing Then
            Response.Redirect("Default.aspx")
        Else
            lblStaffUID.Text = Session("StaffId").ToString
            lblStaffType.Text = Session("StaffType").ToString
        End If

        If Not Page.IsPostBack Then

            CBEBack.ConfirmText = "You are about to navigate away from this page. " & vbCrLf & "Changes will be discard!"

            If Not Request.QueryString("id") Is Nothing Then
                lblAucId.Text = SymmetricDecryptFromHex(Request.QueryString("id"), "augment")
                LoadUpload()
                LoadRelated()
            Else
                Response.Redirect("Default.aspx")
            End If
        End If
    End Sub

    Private Sub LoadUpload()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        objDB.dbVariable.SQLString = "SELECT Daerah, Mukim, Sek, JenisLot, NoLot, TkhPenilaian, LuasLot, UnitLuas, " & _
                                    "JenisHartanah, Alamat, Kawasan, Pemberi, Penerima, Balasan, " & _
                                    "StatusLot,JenisHakmilik,NoHakmilik,JenisPegangan,TempohPajakan,TkhLuputPajakan,JenisBangunan," & _
                                    "BilTktAtasTanah, BilTktBwhTanah, BilBilikTidur, LuasBgnUtama, JenisTanaman, NomborRss, Grid, Syer " & _
                                    "FROM AW_Auction WHERE AucId=@AucId"
        objDB.AddParameter("AucId", Data.SqlDbType.UniqueIdentifier, New Guid(lblAucId.Text))
        objDB.FillData(TempDT, "AW_Auction", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        For Each ReadRow As Data.DataRow In TempDT.Rows
            lblDaerah.Text = ReadRow.Item("Daerah").ToString
            lblMukim.Text = ReadRow.Item("Mukim").ToString
            lblSek.Text = ReadRow.Item("Sek").ToString
            lblJenisLot.Text = ReadRow.Item("JenisLot").ToString
            lblNoLot.Text = ReadRow.Item("NoLot").ToString
            lblTkhPenilaian.Text = ReadRow.Item("TkhPenilaian").ToString
            lblLuasLot.Text = ReadRow.Item("LuasLot").ToString
            lblUnitLuas.Text = ReadRow.Item("UnitLuas").ToString
            lblJenisHartanah.Text = ReadRow.Item("JenisHartanah").ToString
            lblAlamat.Text = ReadRow.Item("Alamat").ToString
            lblKawasan.Text = ReadRow.Item("Kawasan").ToString
            lblPemberi.Text = ReadRow.Item("Pemberi").ToString
            lblPenerima.Text = ReadRow.Item("Penerima").ToString
            lblBalasan.Text = ReadRow.Item("Balasan").ToString
            Label0.Text = ReadRow.Item("StatusLot").ToString
            Label1.Text = ReadRow.Item("JenisHakmilik").ToString()
            Label2.Text = ReadRow.Item("NoHakmilik").ToString()
            Label3.Text = ReadRow.Item("JenisPegangan").ToString()
            Label4.Text = ReadRow.Item("TempohPajakan").ToString()
            Label5.Text = ReadRow.Item("TkhLuputPajakan").ToString()

            Label6.Text = ReadRow.Item("JenisBangunan").ToString()
            Label7.Text = ReadRow.Item("BilTktAtasTanah").ToString()
            Label14.Text = ReadRow.Item("BilTktBwhTanah").ToString()
            Label8.Text = ReadRow.Item("BilBilikTidur").ToString()
            Label9.Text = ReadRow.Item("LuasBgnUtama").ToString()
            Label10.Text = ReadRow.Item("JenisTanaman").ToString()
            Label11.Text = ReadRow.Item("NomborRss").ToString()
            Label12.Text = ReadRow.Item("Grid").ToString()
            Label13.Text = ReadRow.Item("Syer").ToString()
        Next
        objDB.CloseConnection()
    End Sub

    Private Sub LoadRelated()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        objDB.dbVariable.SQLString = "SELECT Alamat, TkhPenilaian, CreateDate FROM AW_Auction WHERE Alamat=@Alamat AND AucId<>@AucId"
        objDB.AddParameter("Alamat", Data.SqlDbType.NVarChar, lblAlamat.Text)
        objDB.AddParameter("AucId", Data.SqlDbType.UniqueIdentifier, New Guid(lblAucId.Text))
        objDB.FillData(TempDT, "AW_Auction", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()
        repUpload.DataSource = TempDT
        repUpload.DataBind()
    End Sub

    Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBack.Click
        If Session("Back") Is Nothing Then
            Response.Redirect("UploadSearch.aspx")
        Else
            Dim strBack As String = Session("Back").ToString
            Dim arr() As String = strBack.Split("ڡ")
            Response.Redirect(arr(0).ToString)
        End If
    End Sub
End Class
